package cn.antblog.code;

import java.text.ParseException;
import java.time.LocalDate;
import java.time.ZonedDateTime;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
 * description: Test
 * date: 2020/10/26 8:51
 * author: YangJy
 */
public class Test {
   
    public int aMethod() {
        /*static int i = 0;
        i++;
        return i;*/
        char i = 1;
        System.out.println(i);

        return 0;

    }

    public static void main(String[] args) throws ParseException {
//        SimpleDateFormat sdf =  new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
//        Date date = new Date();
//        String format = sdf.format(date);
//        Date parse = sdf.parse(format);
//        System.out.println(parse);
//            //innet_month
//
//        System.out.println(format);
        //duibishuzu();
        //SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        //System.out.println(getDaysOfMonth(sdf.parse("2015-02-2")));

        //String timtst = "20210624";
        //System.out.println(timtst.substring(0,4)+"年"+timtst.substring(4,6)+"月"+timtst.substring(6)+"日");
        //lengthOfLongestSubstring("abcbsh");

        //date8Test();

        // full0();
//        String timest = "2021-11-02";
//        SimpleDateFormat format  = new SimpleDateFormat("yyyy-MM-dd");// 获取只有年月日的时间
//        Date date = format.parse(timest);
//        //计算一天前
//        timest = format.format(new Date(date.getTime() - 1 * 24 * 60 * 60 * 1000));
//        System.out.println(timest);
        //char c = 'A'+'B';
        //System.out.println(c);
        //String mmsDate = "20220128";
        //System.out.println(mmsDate.substring(0,4)+mmsDate.substring(4,6)+mmsDate.substring(6,8));

//        String [][] strs = new String [5][];
//        strs[0][0] = "0-0";
//        strs[0][1] = "0-1";
//        strs[0][2] = "0-2";
//        strs[1][0] = "1-0";
//        System.out.println(strs);

//        char sss = 25;
//        System.out.println(sss);
//        String id = "uu&&11";
//        String[] split = split(id, "&&");
//
//        String array = id.substring(1 + id.length());
//        System.out.println(array);

//        Student student = new Student();
//
//        String s = "nihao";
//        s = "头" + s;
//        System.out.println(s);
//
//        int[] myArray;
//        myArray = new int[5];
//        String fileName = "1.txt";
//        fileName.replace(".txt", ".csv");
//        System.out.println(fileName.replace(".txt", ".csv"));

        String t = "你好";
        System.out.println("t = " + t);
        System.out.println("t = " + t.intern());

        String s1 = new String("二哥三妹");
        String s2 = s1.intern();
        System.out.println(s1 == s2);

        String str1 = new StringBuilder("58").append("tongcheng").toString();
        System.out.println(str1);
        System.out.println(str1.intern());
        System.out.println(str1 == str1.intern()); //true

        System.out.println();

        String str2 = new StringBuilder("ja1").append("va").toString();
        System.out.println(str2);
        System.out.println(str2.intern());
        System.out.println(str2 == str2.intern()); //false

        Date date = new Date();
        System.out.println("date = " + date);
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println("now = " + now);


        String da = "2022-06-22 06:23:00";
        String dateTime = "2022-06-22 06:23:00";
        String substring = da.substring(5, 7);
        String substring2 = da.substring(8, 10);
        String substring3 = da.substring(11, 13);
        String substring4 = da.substring(14, 16);
        String dateTimeUp = Integer.valueOf(dateTime.substring(5, 7)) + "月" + Integer.valueOf(dateTime.substring(8, 10)) + "日" + Integer.valueOf(dateTime.substring(11, 13)) + ":" + Integer.valueOf(dateTime.substring(14, 16)) + "点";

        System.out.println("substring = " + Integer.valueOf(substring));
        System.out.println("substring2 = " + substring2);
        System.out.println("substring3 = " + substring3);
        System.out.println("substring4 = " + substring4);
        System.out.println("dateTimeUp = " + dateTimeUp);


    }

    public static String[] split(String array, String target) {
        List<String> list = new ArrayList<>();
        while (array.contains(target)) {
            int index = array.indexOf(target);
            String temp = array.substring(0, index);
            list.add(temp);
            array = array.substring(index + target.length()); //substring(endIndex)删除endIndex之前的字符串
        }
        list.add(array);
        String[] arr = new String[list.size()];
        for (int i = 0; i < list.size(); i++) {
            arr[i] = list.get(i);
        }
        return arr;
    }


    //没有的补0  用于日期中缺少数据 补0 来构成折线图
    public static List<Map<String, Object>> full0() {
        List<String> list = new ArrayList<>();
        list.add("20210720");
        list.add("20210721");
        list.add("20210722");
        list.add("20210723");
        list.add("20210724");
        list.add("20210725");
        list.add("20210726");
        System.out.println("日期：" + list.toString());
        List<Map<String, Object>> mapList = new LinkedList<>();
        HashMap<String, Object> hashMap0721 = new HashMap<>();
        hashMap0721.put("20210721", "0721");
        mapList.add(hashMap0721);
        HashMap<String, Object> hashMap0725 = new HashMap<>();
        hashMap0725.put("20210725", "0725");
        mapList.add(hashMap0725);
        System.out.println("数据：" + mapList.toString());
        int sizeList = list.size();
        int sizeMapList = mapList.size();
        if (sizeList > sizeMapList) {
            for (int i = 0; i < list.size(); i++) {
                int flag = 0;
                for (Map<String, Object> stringObjectMap : mapList) {
                    if (!stringObjectMap.containsKey(list.get(i))) {
                        flag++;
                    } else {
                        flag--;
                    }
                }
                //System.out.println(flag+"|"+mapList.size());
                if (flag == mapList.size()) {
                    HashMap<String, Object> hashMap = new HashMap<>();
                    hashMap.put(list.get(i), "新增");
                    mapList.add(i, hashMap);
                }
            }
        }
        System.out.println(mapList.toString());
        return null;
    }

    public static void date8Test() {
        String dateStr = "2021-07-08";
        DateTimeFormatter df = DateTimeFormatter.ofPattern("yyyy-MM-dd");
        DateTimeFormatter df1 = DateTimeFormatter.ofPattern("yyyyMMdd");
        LocalDate localDate = LocalDate.parse(dateStr, df);
        LocalDate localDate1 = localDate.minusDays(10);
        String toString = df1.format(localDate1);
        System.out.println(localDate);
        System.out.println(localDate1);
        System.out.println(toString);
    }


    //（Java）给定一个字符串，请你找出其中不含有重复字符的 最长子串 的长度。
    public static int lengthOfLongestSubstring(String s) {
        int n = s.length(), ans = 0;
        int[] index = new int[128]; // current index of character
        // try to extend the range [i, j]
        for (int j = 0, i = 0; j < n; j++) {
            int p = index[s.charAt(j)];
            i = Math.max(p, i);
            ans = Math.max(ans, j - i + 1);
            int idx = s.charAt(j);
            index[idx] = j + 1;
        }
        System.out.println(ans);
        return ans;
    }

    public static void duiBiShuZu() {
        int[] arr1 = new int[]{1, 4, 3, -2, 6, 5, 3, 5, 9, 0, 0};
        int[] arr2 = new int[]{1, 4, 3, -2, 6, 5, 3, 5, 9, 0, 2};
        int m = 0;
        int n = 0;
        if (arr1.length != arr2.length) {
            System.out.println("数组长度不相等" + "\n数组1：" + arr1.length + "\n数组2：" + arr2.length);
            return;
        }
        for (int i = 0; i < arr1.length; i++) {
            m += arr1[i];
            n += arr2[i];
        }
        if (m != n) {
            System.out.println("数组元素不相同");
            return;
        }
        for (int i = 0; i < arr1.length; i++) {
            m = arr1[i];
            n = arr2[i];
            if (m != n) {
                System.out.println("数组元素顺序不相等" + "\n不相等索引号：" + i);
                return;
            }
        }
        System.out.println("两个数组完全相同");
    }


    public static int getDaysOfMonth(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(new Date());
        return calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
    }


}
